package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsPermissionMapper;
import com.qf.pojo.DtsPermission;
import com.qf.service.DtsPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class DtsPermissionServiceImpl implements DtsPermissionService {

    @Autowired
    DtsPermissionMapper permissionMapper;

    @Override
    public Set<String> findPermsByRoleIds(Integer[] roleIds) {

        LambdaQueryWrapper<DtsPermission> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(DtsPermission::getRoleId , roleIds);
        wrapper.eq(DtsPermission::getDeleted, false);

        List<DtsPermission> permissions = permissionMapper.selectList(wrapper);

        Set<String> set = permissions.stream().map(permission -> {
            return permission.getPermission();
        }).collect(Collectors.toSet());

        return set;
    }
}
